package com.myspace.server.user.controller;

import com.myspace.server.base.util.JsonView;
import com.myspace.server.base.util.JsonViewFactory;
import com.myspace.server.user.entity.User;
import com.myspace.server.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制器
 * @author peng.zhang
 */
@Api(tags = "user")
@RestController
@RequestMapping(value = "/user")
public class UserController {

    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation(value = "查询用户信息", notes = "根据用户 ID 查询用户信息")
    @ApiImplicitParam(name = "uid", value = "用户 ID", required = true, paramType = "path", dataTypeClass = Long.class, dataType = "Long")
    @GetMapping(value = "/info/{uid}")
    public JsonView getUserInfo(@PathVariable Long uid) {
        JsonView jsonView = JsonViewFactory.createJsonView();
        try {
            User user = userService.getByPrimaryKey(uid);
            jsonView.successPack(user);
        } catch (Exception e) {
            jsonView.errorPack("getUserInfo(/user/info/{uid}) error", e);
        }
        return jsonView;
    }

}
